<template>
	<view class="page page-order">
		<!-- 筛选 -->
		<view class="filter-bar flex-row-between">
			<block v-for="(item, index) in filterBar" :key="index">
				<view class="item" :class="{'active' : filterCurrent == item.id}" @click="filterList(item.id)">{{item.title}}</view>
			</block>
		</view>
		<!-- 列表 -->
		<view class="prescript-list">
			<LoadMore ref="LoadMore" id="LoadMore" :diffHeight="72" :initData="initData" @dataRefresh='dataRefresh'>
				<block v-for="(item, index) in dataList" :key="index">
					<view class="item" @click="goNext('/pagesA/prescript/doctorOrderDetail?id=' + item.id)">
						<view class="part1 flex-row-between">
							<view class="font13">诊断结果：{{item.diagnose}}</view>
							<view class="font12 font-ef9140">{{item.status_text}}</view>
						</view>
						<view class="part2">
							<text class="font13">用药建议：</text>
							<!-- 此处最多展示2个药品 -->
							<block v-for="(drug, i) in item.goods_list" :key="i">
								<view v-if="i < 2" class="font12 font-969696">
									<text>{{drug.goods_name}} {{drug.spec_name}} *{{drug.number}}</text>
									<text v-if="i == 1">...</text>
								</view>
							</block>
						</view>
						<view class="doctor font12 font-969696 flex-row-start">
							<view class="photo bg-cover" :style="{backgroundImage: 'url(' + photo + ')'}"></view>
							<text>{{item.user_the_patient_info.name}}</text>
							<text>{{item.createtime}}</text>
						</view>
						<view class="part3 flex-row-end">
							<view v-if="item.status != 'yes'" class="btn-small grey" @click.stop="onCancel(item.id)">取消</view>
							<view v-if="item.status == 'reject'" class="btn-small green" @click.stop="onEdit(item)">编辑</view>
						</view>
						<uni-icons class="icon" type="arrowright" size="14" color="#969696"></uni-icons>
					</view>
				</block>
			</LoadMore>
		</view>
	</view>
</template>

<script>
	import LoadMore from "@/components/loadMore.vue";
	export default {
		components: { LoadMore },
		data() {
			return {
				photo: require('../../static/my/portrait.png'),
				filterBar: [
					{ id: '', title: '全部'},
					{ id: 'normal', title: '待审核'},
					{ id: 'yes', title: '已通过'},
					{ id: 'reject', title: '已驳回'}
				],
				filterCurrent: '', // 高亮的id
				// 传参数据
				initData: {
					url: 'listPrescription3',
					param: {
						status: ''
					}
				},
				dataList:[],
			}
		},
		methods: {
			// 筛选列表
			filterList (id) {
				this.filterCurrent = id
				this.initData.param.status = id
				this.$refs.LoadMore.oncutRefresh(this.initData)
			},
			//返回数据
			dataRefresh(e) {
				let $this = this
				e.forEach(item => {
					if (item.doctor_info) {
						item.doctor_info.img = $this.$store.state.http_img + item.doctor_info.img
					}
				})
				this.dataList = e
			},
			// 取消
			onCancel (id) {
				let that = this
				uni.showModal({
					title: '提示',
					confirmText: '确认',
					confirmColor: '#b8875c',
					cancelText: '取消',
					content: '您确定要取消吗?',
					success: function(res) {
						if (res.confirm) {
							that.$Http({
								url: 'hiddenPrescription',
								data: {doctor_prescription_id: id}
							}).then(res => {
								if (res.code == 1) {
									uni.showToast({ title: '操作成功' })
									that.$refs.LoadMore.oncutRefresh(that.initData)
								} else {
									uni.showToast({ title: res.msg, icon: 'none' })
								}
							})
						}
					}
				});
			},
			// 编辑
			onEdit (item) {
				let familyId = item.user_the_patient_info.id
				let doctorId = item.doctor_info.id
				uni.navigateTo({
					url:  '/pagesA/prescript/newPrescript?familyId=' + familyId + '&doctorId=' + doctorId + '&prescriptId=' + item.id + '&type=history'
				})
			},
			goNext (url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>
